<?php

namespace App\Models;

class OrderAddress extends BaseModel
{
    public $timestamps = true;
    public $table = 'order_address';
    static $unguarded = true;

    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';

    /**
     * 获取当前时间
     *
     * @return int
     */
    public function freshTimestamp()
    {
        return time();
    }

    /**
     * 避免转换时间戳为时间字符串
     *
     * @param DateTime|int $value
     * @return DateTime|int
     */
    public function fromDateTime($value)
    {
        return $value;
    }

    public function province()
    {
        return $this->hasOne(LouAddress::class, 'id', 'province_id');
    }

    public function getProvinceTitle()
    {
        return $this->province->title;
    }

    public function city()
    {
        return $this->hasOne(LouAddress::class, 'id', 'city_id')->select("title");
    }

    public function getCityTitle()
    {
        return $this->city->title;
    }

    public function region()
    {
        return $this->hasOne(LouAddress::class, 'id', 'region_id');
    }

    public function getRegion()
    {
        return $this->region->title;
    }

    public function district()
    {
        return $this->hasOne(LouAddress::class, 'id', 'district');
    }

    public function getDistrict()
    {
        return $this->district->title;
    }
}